
//
//  MCBaseCell.m
//  MapleCell
//
//  Created by 赵磊 on 2019/8/1.
//

#import "MCBaseCell.h"

@interface MCBaseCell ()

@end

@implementation MCBaseCell

#pragma mark - Lazy
- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        imageView.layer.cornerRadius = 6.0;
        imageView.layer.masksToBounds = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.backgroundColor = [UIColor colorWithRed:(243 + (arc4random()%12)) / 255.0 green:(243 + (arc4random()%12)) / 255.0 blue:(243 + (arc4random()%12)) / 255.0 alpha:1.0];
        [self.contentView addSubview:imageView];
        _iconImageView = imageView;
    }
    return _iconImageView;
}
- (UIButton *)iconButton {
    if (!_iconButton) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectZero];
        button.userInteractionEnabled = NO;
        [self.contentView addSubview:button];
        _iconButton = button;
    }
    return _iconButton;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.textColor = [UIColor colorWithWhite:51 / 255.0 alpha:1.0];
        label.font = [UIFont systemFontOfSize:16.0];
        [self.contentView addSubview:label];
        _titleLabel = label;
    }
    return _titleLabel;
}
- (UILabel *)subTitleLabel {
    if (!_subTitleLabel) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.textColor = [UIColor colorWithWhite:153 / 255.0 alpha:1.0];
        label.font = [UIFont systemFontOfSize:15.0];
        [self.contentView addSubview:label];
        _subTitleLabel = label;
    }
    return _subTitleLabel;
}
- (UIButton *)arrowButton {
    if (!_arrowButton) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(UIScreen.mainScreen.bounds.size.width - 40.0, 0, 40.0, [MCBaseCell baseHeight])];
        NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
        NSString *bundleName = [[currentBundle.resourcePath componentsSeparatedByString:@"/"].lastObject componentsSeparatedByString:@"."].firstObject;
        NSString *imageName = [NSString stringWithFormat:@"%@.bundle/MCBaseCell_arrow@%dx.png",bundleName,(int)UIScreen.mainScreen.scale];
        NSString *imagePath = [currentBundle.resourcePath stringByAppendingPathComponent:imageName];
        UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
        [button setImage:image forState:UIControlStateNormal];
        [self.contentView addSubview:button];
        _arrowButton = button;
    }
    return _arrowButton;
}
- (CALayer *)bottomLine {
    if (!_bottomLine) {
        CALayer *layer = [CALayer layer];
        layer.backgroundColor = [UIColor colorWithWhite:220 / 255.0 alpha:1.0].CGColor;
        layer.frame = CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 0.5);
        [self.contentView.layer addSublayer:layer];
        _bottomLine = layer;
    }
    return _bottomLine;
}

#pragma mark - ReuseAndCreate
+ (CGFloat)baseHeight {
    return 60.0;
}
+ (instancetype)reuseCell:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath {
    MCBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MCBaseCell class])];
    if (!cell) {
        cell = [[self alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:NSStringFromClass([MCBaseCell class])];
        cell.selectionStyle = NO;
    }
    return cell;
}

@end
